package com.bsj.pay.util.platform.wsgw;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bsj.pay.model.GoodsBean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.bsj.pay.common.ChargeOrder;
import com.bsj.pay.config.GlobalConfig;
import com.bsj.pay.model.AccountBean;
import com.bsj.pay.model.ChargeAccountBean;
import com.bsj.pay.model.OrderBean;
import com.bsj.pay.service.AccountService;
import com.bsj.pay.service.ChargeAccountService;
import com.bsj.pay.util.date.DateTimeUtil;
import com.bsj.pay.util.http.Http;
import com.bsj.pay.util.http.Http.RequestType;
import com.bsj.pay.util.http.Http.Response;
import com.bsj.pay.util.platform.PlatformInterface;
import com.bsj.pay.util.security.MD5;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Component("wsgwUtil")
public class WsgwUtil implements PlatformInterface{
    private static final Logger log = LogManager.getLogger(WsgwUtil.class);
    
    private static String queryOrderType = "order";
    
    @Autowired
    private AccountService accountService;
    
    @Autowired
    private ChargeAccountService chargeAccountService;
    
    public Map<String, String> createOrder(ChargeAccountBean chargeAccount, GoodsBean goods, AccountBean account, OrderBean order) throws Exception {
    	Map<String, String> orderMap = null;
    	for(int i=0;i<3;i++){
    		try {
    			orderMap = createOrderPre(chargeAccount,account,order);
    			return getPayUrl(orderMap, order.getPay_type(), account);
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			if(e.getMessage()!=null&&i<2)
    			{
    				if(e.getMessage().contains("网络链接失败")){
        				log.info("账号:{},下单网络链接失败,重新绑定代理ip",account.getAccount());
        				accountService.updateAccountProxy(account);
        			}
        			else if(e.getMessage().contains("未获取到ORDER_CENTRE_ORDER_ID")){
        				Thread.sleep(1000);
        			}
    			}
    			else {throw e;}
    		}
    	}
    	return null;
    }
    
    public Map<String,String> getPayUrl(Map<String,String> orderMap,String payType,AccountBean account) throws Exception {
    	Map<String, String> resultMap = new HashMap<String, String>();
    	Map<String, String> headers = new HashMap<String, String>();
    	String url="https://payctl.95598pay.com/payunifycontroller/rest/payunify/zfbpay";
    	if(payType.startsWith("wechat"))
    	{
    		url="https://payctl.95598pay.com/payunifycontroller/rest/payunify/wxpay";
    	}
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("version", "2.2.3");
     	String bodys="data={\"data\":{\"PRE_ORDER_ID\":\""+orderMap.get("ORDER_ID")+"\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"header\":{\"REQTYPE\":\"1\",\"TIMESTAMP\":\"X2MmXeMHXejmXeUlXlXJY29A\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"CHANNEL_RESOURCE\":\"5\",\"SDKVERSION\":\"1.2021.05.14.01\",\"PLAT\":\"2\"}}";
     	Response res = Http.create(url).proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(bodys).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
             throw new Exception("网络链接失败，请重试!");
        }
        JSONObject jsonObject=JSONObject.fromObject(result);
        jsonObject=jsonObject.getJSONObject("data");
        String ERRORMESSAGE=jsonObject.optString("ERRORMESSAGE","");
        if(!StringUtils.isEmpty(ERRORMESSAGE))
        {
        	throw new Exception(ERRORMESSAGE);
        }
        String MERORDERID=jsonObject.getString("MERORDERID");
        String payUrl=jsonObject.getString("PAY_PARAM");
        if(payType.startsWith("wechat"))
        {
        	JSONObject dataObj = JSONObject.fromObject(payUrl);
            String prepayid = dataObj.getString("prepayId");
            String appid = dataObj.getString("appId");
            String packageStr = dataObj.getString("packageValue");
            String partnerid = dataObj.getString("partnerId");
            String noncestr = dataObj.getString("nonceStr");
            String signStr = dataObj.getString("sign");
            String timestamp = dataObj.getString("timeStamp");
            StringBuffer payBuffer = new StringBuffer();
            payBuffer.append("weixin://app/").append(appid).append("/pay/?nonceStr=").append(noncestr).append("&package=").append(URLEncoder.encode(packageStr)).append("&partnerId=").append(partnerid).append("&prepayId=").append(prepayid).append("&timeStamp=").append(timestamp).append("&sign=").append(signStr).append("&signType=").append("SHA1");
            resultMap.put("payUrl", payBuffer.toString());
        }
        else
        {
        	resultMap.put("payUrl", payUrl);
        }
		log.info("[网上国网]获取支付链接---订单号:{},交易号:{},结果:{},耗时:{},状态:{}",orderMap.get("ORDER_ID"),MERORDERID,resultMap.get("payUrl"),res.getTime(),res.getStatus());
		resultMap.put("orderNo", orderMap.get("ORDER_CENTRE_ORDER_ID")+"_"+orderMap.get("ORDER_ID"));
     	return resultMap;
    }

    
    public Map<String,String> orderDetail1(OrderBean order,AccountBean account) throws Exception {
    	Map<String, String> resultMap = new HashMap<String, String>();
    	resultMap.put("orderNo", "");
    	resultMap.put("status", "fail");
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"orderId\":\""+order.getOfficial_order_no()+"\",\"token\":\""+account.getLogin_cookie()+"\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-service.sgcc.com.cn:18600/osg-oc0002/member/c1/f02?_="+timestamp).proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询订单信息---订单号:{},耗时:{},状态:{}",order.getOfficial_order_no(),res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			throw new Exception(jsonObject.getString("message"));
		}
		jsonObject = jsonObject.getJSONObject("data");
		if("3".equals(jsonObject.getString("orderStatus")))
		{
			resultMap.put("orderNo", order.getOfficial_order_no());
			resultMap.put("status", "success");
		}
     	return resultMap;
    }
    
    public Map<String,String> online(AccountBean account) throws Exception {
    	AccountBean updateModel=new AccountBean();
    	updateModel.setId(account.getId());
    	if(!StringUtils.isEmpty(account.getLogin_cookie())) {
    		Map<String,String> resultMap=this.queryCertAuth(account);
    		updateModel.setAuth_status(Integer.parseInt(resultMap.get("rlAuth")));
    		updateModel.setLogin_status(1);
    		accountService.update(updateModel);
    	}
    	else if(!StringUtils.isEmpty(account.getPassword())){
    		Map<String,String> resultMap=this.login(account);
    		updateModel.setLogin_cookie(resultMap.get("token"));
    		updateModel.setInfo(resultMap.get("userId"));
    		updateModel.setUpdate_time(System.currentTimeMillis()/1000);
    		accountService.update(updateModel);
    	}
        return null;
    }
    
    public Map<String, String> login(AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	String body="{\"avalonValidCode\":\"\",\"quInfo\":{\"optSys\":\"Ios\",\"pushId\":\"000000,000000\",\"addressProvince\":\"420000\",\"password\":\""+MD5.getMD5(account.getPassword())+"\",\"addressRegion\":\"\",\"account\":\""+account.getAccount()+"\",\"addressCity\":\"420100\"},\"uscInfo\":{\"devciceIp\":\""+account.getProxy_ip()+"\",\"member\":\"2202\",\"tenant\":\"state_grid\",\"isEncrypt\":\"false\",\"devciceId\":\"863938053895790\"}}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-service.sgcc.com.cn:18600/osg-uc0012/member/c2/ftn1001").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]账号登录---账号:{},结果:{},耗时:{},状态:{}",account.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			throw new Exception(jsonObject.getString("message"));
		}
		jsonObject = jsonObject.getJSONObject("data");
		JSONObject srvrt=jsonObject.getJSONObject("srvrt");
		if(!"0000".equals(srvrt.getString("resultCode")))
		{
			throw new Exception(srvrt.getString("resultMessage"));
		}
		Map<String,String> resultMap=new HashMap<String,String>();
		JSONObject bizrt=jsonObject.getJSONObject("bizrt");
		resultMap.put("token", bizrt.getString("token"));
    	bizrt=bizrt.getJSONObject("userInfo");
    	resultMap.put("userId", bizrt.getString("userId"));
    	return resultMap;
    }
    
    public Map<String, String> createOrderPre(ChargeAccountBean chargeAccount,AccountBean account,OrderBean order) throws Exception {
    	//Map<String,String> orderMap=addAccount(chargeAccount, account);
    	//float LEAST_PAY_AMOUNT = Float.parseFloat(orderMap.get("LEAST_PAY_AMOUNT"))/100;
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	int orderAmount=order.getAmount()*100;
     	SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS");
     	String orderTime=sdf.format(new Date());
     	String body="{\"data\":{\"common\":{\"APPVERSION\":\"2.2.3\",\"CHANNEL_RESOURCE\":\"5\","
     			+ "\"ENCRYPTTYPE\":\"0\",\"PLAT\":\"3\",\"REQTYPE\":\"1\",\"SDKVERSION\":\"1.2021.05.14.01\","
     			+ "\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"data\":{\"MSG_PSW\":\"\",\"WALLET_ACCDUC_AMOUNT\":\"0\","
     			+ "\"REDUCE_AMOUNT\":\"0\",\"INTEGRAL_AMOUNT\":\"0\",\"PAY_PWD_LEVE\":\"\",\"COUPON_AMOUNT\":\"0\",\"INTEGRAL_NUM\":\"0\","
     			+ "\"POWER_LIST\":[{\"SUB_REDUCE_AMOUNT\":\"0\",\"IS_CONSNO_FLAG\":\"false\","
     			+ "\"SUB_PAY_AMOUNT\":\""+orderAmount+"\",\"SUB_COUPON_LIST\":[],\"SUB_INTEGRAL_AMOUNT\":\"0\","
     			+ "\"SUB_WALLET_ACCDUC_AMOUNT\":\"0\",\"SENSITIVE_POWER_USER_ID\":\""+chargeAccount.getOfficial_user_id()+"\","
     			+ "\"PROVINCE_CODE\":\""+chargeAccount.getArea_code()+"\",\"POWER_USER_ID\":\""+chargeAccount.getAccount()+"\",\"SUB_ORDER_AMOUNT\":\""+orderAmount+"\"}],"
     			+ "\"ORDER_AMOUNT\":\""+orderAmount+"\",\"PAY_MARK\":\"\",\"PAY_PWD\":\"\",\"PAY_AMOUNT\":\""+orderAmount+"\",\"ORDER_SOURCE\":\"01\","
     			+ "\"COUPON_LIST\":[],\"CONST_ID\":\"\",\"ORDER_TIME\":\""+orderTime+"\",\"CHANNEL_SYSNO\":\"1000000002\",\"TOKEN\":"
     			+ "\""+account.getLogin_cookie()+"\"}},\"serviceCode\":\"f05\",\"source\":\"undefined\",\"target\":\"undefined\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-base.sgcc.com.cn:28660/osg-p0002/member/p2/f01").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
             throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]下单---账号:{},结果:{},耗时:{},状态:{}",account.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"0".equals(code)) {
			String message=jsonObject.getString("message");
			//!message.contains("避免重复交费")&&!message.contains("明日再试")&&!message.contains("无法再次交费")&&!message.contains("只允许交费一次")&&
			if(!message.contains("稍后再试")&&!message.contains("重新登录")&&!message.contains("实名")&&!message.contains("认证参数为空"))
			{
				chargeAccount.setStatus(-2);
//				if(chargeAccount.getCharge_status()==1)chargeAccount.setCharge_status(1);
			}
			if(chargeAccount.getBind_fail_count()>5)
			{
				chargeAccount.setStatus(-2);
				if(chargeAccount.getCharge_status()==1)chargeAccount.setCharge_status(1);
				else{
					chargeAccount.setCharge_status(-1);
				}
				chargeAccount.setRemarks("充值失败次数超过5次!原因:"+message);
			}
			else if(message.contains("繁忙")||message.contains("欠费信息异常"))
			{
				chargeAccountService.addBindFailCount(chargeAccount.getId());
			}
    		 
			throw new Exception(message);
		}
		jsonObject = jsonObject.getJSONObject("data").getJSONObject("data");
		Map<String,String> resultMap=new HashMap<String,String>();
		String ORDER_CENTRE_ORDER_ID=jsonObject.optString("ORDER_CENTRE_ORDER_ID","");
		if(StringUtils.isEmpty(ORDER_CENTRE_ORDER_ID))
		{
			throw new Exception("下单失败,未获取到ORDER_CENTRE_ORDER_ID");
		}
		String ORDER_ID=jsonObject.optString("ORDER_ID","");
		if(StringUtils.isEmpty(ORDER_ID))
		{
			throw new Exception("下单失败,未获取到ORDER_ID");
		}
		resultMap.put("ORDER_CENTRE_ORDER_ID",ORDER_CENTRE_ORDER_ID);
    	resultMap.put("ORDER_ID", ORDER_ID);
    	return resultMap;
    }
    
    public List<ChargeAccountBean> queryAccountList(AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"data\":{\"common\":{\"APPVERSION\":\"2.2.3\",\"CHANNEL_RESOURCE\":\"5\",\"ENCRYPTTYPE\":\"0\",\"PLAT\":\"3\",\"REQTYPE\":\"1\",\"SDKVERSION\":\"1.2021.05.14.01\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"data\":{\"ELEC_TYPE\":\"01\",\"SENSITIVE_POWER_USER_ID\":\"\",\"TYPE\":\"0\",\"PROVINCE_CODE\":\"\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"POWER_USER_ID\":\"\"}},\"serviceCode\":\"f05\",\"source\":\"undefined\",\"target\":\"undefined\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-base.sgcc.com.cn:28660/osg-p0002/member/p1/f01").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).timeout(6).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询户号列表---账号:{},结果:{},耗时:{},状态:{}",account.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		List<ChargeAccountBean> list=new ArrayList<ChargeAccountBean>();
		String code=jsonObject.getString("code");
		if(!"0".equals(code)) {
			String message=jsonObject.getString("message");
			if(message.contains("请先添加交费户号"))
			{
				return list;
			}
			else throw new Exception(message);
		}
		jsonObject = jsonObject.getJSONObject("data").getJSONObject("data");
		JSONArray ELEC_TYPE_LIST=jsonObject.getJSONArray("ELEC_TYPE_LIST");
		if(ELEC_TYPE_LIST.isEmpty())return list;
		for(int i=0;i<ELEC_TYPE_LIST.size();i++)
		{
			JSONObject elec_type=ELEC_TYPE_LIST.getJSONObject(i);
			JSONArray ARREARS_LIST=elec_type.getJSONArray("ARREARS_LIST");
			if(!ARREARS_LIST.isEmpty())
			{
				for(int j=0;j<ARREARS_LIST.size();j++)
				{
					JSONObject elec=ARREARS_LIST.getJSONObject(j);
					int type=1;
					if("02".equals(elec_type.getString("ELEC_TYPE")))type=2;
					ChargeAccountBean chargeAccount=new ChargeAccountBean();
					chargeAccount.setType(type);
					chargeAccount.setAccount(elec.getString("POWER_USER_ID"));
					chargeAccount.setOfficial_user_id(elec.getString("SENSITIVE_POWER_USER_ID"));
					chargeAccount.setArea_code(elec.getString("PROVINCE_CODE"));
					list.add(chargeAccount);
				}
			}
		}
    	return list;
    }
    
    public Map<String, String> addAccount(ChargeAccountBean chargeAccount,AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"data\":{\"common\":{\"APPVERSION\":\"2.2.3\",\"CHANNEL_RESOURCE\":\"5\",\"ENCRYPTTYPE\":\"0\",\"PLAT\":\"3\",\"REQTYPE\":\"1\",\"SDKVERSION\":\"1.2021.05.14.01\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"data\":{\"ELEC_TYPE\":\"01\",\"TYPE\":\"1\",\"PROVINCE_CODE\":\""+chargeAccount.getArea_code()+"\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"POWER_USER_ID\":\""+chargeAccount.getAccount()+"\"}},\"serviceCode\":\"f05\",\"source\":\"undefined\",\"target\":\"undefined\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-base.sgcc.com.cn:28660/osg-p0002/member/p1/f01").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]绑定户号---账号:{},户号:{},结果:{},耗时:{},状态:{}",account.getAccount(),chargeAccount.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"0".equals(code)) {
			String message=jsonObject.getString("message");
			if(message.contains("请输入正确的用电户号")) {
				chargeAccount.setStatus(-2);
				chargeAccount.setCharge_status(-1);
			}
			throw new Exception(message);
		}
		jsonObject = jsonObject.getJSONObject("data").getJSONObject("data");
		JSONArray ELEC_TYPE_LIST=jsonObject.getJSONArray("ELEC_TYPE_LIST");
		jsonObject = ELEC_TYPE_LIST.getJSONObject(0);
		JSONArray ARREARS_LIST=jsonObject.getJSONArray("ARREARS_LIST");
		jsonObject=ARREARS_LIST.getJSONObject(0);
		String POWER_USER_ID=jsonObject.getString("POWER_USER_ID");
		if(!chargeAccount.getAccount().equals(POWER_USER_ID))
		{
			throw new Exception("新增户号"+chargeAccount.getAccount()+"，失败");
		}
		//String AVALIABLE_BALANCE=jsonObject.optString("AVALIABLE_BALANCE","0");
		//if("null".equals(AVALIABLE_BALANCE)){
		//	AVALIABLE_BALANCE="0";
		//}
		String LEAST_PAY_AMOUNT=jsonObject.optString("LEAST_PAY_AMOUNT","0");
		if("null".equals(LEAST_PAY_AMOUNT)){
			LEAST_PAY_AMOUNT="0";
		}
		//int ava=Integer.parseInt(AVALIABLE_BALANCE);
		//int lea=Integer.parseInt(LEAST_PAY_AMOUNT);
		//if(ava<0&&Math.abs(ava)>lea) {
		//	LEAST_PAY_AMOUNT=String.valueOf(Math.abs(ava));
		//}
		String SENSITIVE_POWER_USER_ID=jsonObject.getString("SENSITIVE_POWER_USER_ID");
		Map<String,String> resultMap=new HashMap<String,String>();
		resultMap.put("LEAST_PAY_AMOUNT" , LEAST_PAY_AMOUNT);
		resultMap.put("SENSITIVE_POWER_USER_ID" , SENSITIVE_POWER_USER_ID);
    	resultMap.put("POWER_USER_ID", POWER_USER_ID);
    	return resultMap;
    }
    
    public Map<String, String> queryAccount(AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"quInfo\":{\"passWord\":\"\",\"avalonValidCode\":\"\",\"proNo\":\"42102\",\"cityCode\":\"\",\"consNo\":\"8570109487\",\"provinceId\":\"420000\"},\"uscInfo\":{\"deviceIp\":\""+account.getProxy_ip()+"\",\"member\":\"2202\",\"deviceId\":\"863938053895790\",\"tenant\":\"state_grid\",\"isEncrypt\":false},\"token\":\""+account.getLogin_cookie()+"\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-service.sgcc.com.cn:18600/osg-uc0015/member/c3/f02").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询用户信息---账号:{},户号:{},结果:{},耗时:{},状态:{}",account.getAccount(),"8570109487",result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			String message=jsonObject.getString("message");
			throw new Exception(message);
		}
		if(!(jsonObject.get("data") instanceof JSONObject))
		{
			throw new Exception("账号查询异常");
		}
    	return null;
    }
    
    public Map<String, String> queryCertAuth(AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"data\":{\"common\":{\"APPVERSION\":\"\",\"CHANNEL_RESOURCE\":\"05\",\"IP\":\""+account.getProxy_ip()+"\",\"PLAT\":\"android\",\"ENCRYPTTYPE\":\"\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"UNIONID\":\"\"},\"data\":{\"USERID\":\"\"}},\"serviceCode\":\"f06\",\"source\":\"app\",\"target\":\"33101\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-base.sgcc.com.cn:28660/osg-uc0012/auth/member/c1/f06").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询实名信息---账号:{},结果:{},耗时:{},状态:{}",account.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			String message=jsonObject.getString("message");
			throw new Exception(message);
		}
		if(!(jsonObject.get("data") instanceof JSONObject))
		{
			throw new Exception("实名信息查询异常");
		}
		JSONObject authTypeJson=JSONObject.fromObject(jsonObject.getJSONObject("data").getJSONObject("data").optString("AUTH_TYPE","{}"));
		String rlAuth=authTypeJson.optString("04","0");
		Map<String,String> resultMap=new HashMap<String,String>();
		resultMap.put("rlAuth" , rlAuth);
    	return resultMap;
    }
    
    public boolean delAccount(ChargeAccountBean chargeAccount,AccountBean account) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"data\":{\"common\":{\"APPVERSION\":\"2.2.3\",\"CHANNEL_RESOURCE\":\"5\",\"ENCRYPTTYPE\":\"0\",\"PLAT\":\"3\",\"REQTYPE\":\"1\",\"SDKVERSION\":\"1.2021.05.14.01\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"data\":{\"SENSITIVE_POWER_USER_ID\":\""+chargeAccount.getOfficial_user_id()+"\",\"PROVINCE_CODE\":\""+chargeAccount.getArea_code()+"\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"POWER_USER_ID\":\""+chargeAccount.getAccount()+"\"}},\"serviceCode\":\"f05\",\"source\":\"undefined\",\"target\":\"undefined\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-base.sgcc.com.cn:28660/osg-p0002/member/c9/f03").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).timeout(6).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]解绑户号---账号:{},户号:{},结果:{},耗时:{},状态:{}",account.getAccount(),chargeAccount.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"0".equals(code)) {
			String message=jsonObject.getString("message");
			throw new Exception(message);
		}
		jsonObject = jsonObject.getJSONObject("data").getJSONObject("data");
		if("0".equals(jsonObject.getString("RESULT"))&&jsonObject.getString("MESSAGE").equals("删除成功"))
		{
			return true;
		}
    	return false;
    }
    
    public List<ChargeOrder> queryTransList(AccountBean account,boolean status) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"busyTypeCode\":\"\",\"srcTypeCode\":\"01\",\"subBusyTypeCode\":\"\",\"eStatusTypeCode\":\"\",\"showTime\":\"\",\"pageSize\":100,\"list\":[],\"keyWord\":\"\",\"token\":\""+account.getLogin_cookie()+"\",\"accountId\":\""+account.getInfo()+"\",\"rStatusTypeCode\":\"\",\"sSubBusyTypeCode\":\"\",\"sStatusTypeCode\":\"\",\"pageNo\":1,\"startTime\":\"\",\"busyNo\":\"\",\"endTime\":\"\",\"serviceTypeCode\":\"\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-service.sgcc.com.cn:18600/osg-uc0004/member/c2/f02").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).timeout(6).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询订单列表---账号:{},耗时:{},状态:{}",account.getAccount(),res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			throw new Exception(jsonObject.getString("message"));
		}
		List<ChargeOrder> onlineOrderList=new ArrayList<ChargeOrder>();
		if(!(jsonObject.get("data") instanceof JSONArray))return onlineOrderList;
		JSONArray orderList = jsonObject.getJSONArray("data");
		if(orderList.isEmpty())return onlineOrderList;
		for (int i = 0; i < orderList.size(); i++) {
			JSONObject data = orderList.getJSONObject(i);
			JSONObject serContent = data.getJSONObject("serContent");
			String orderStatus = serContent.optString("orderStatus");
			if(status&&!"3".equals(orderStatus))continue;
			ChargeOrder cOrder=new ChargeOrder();
			cOrder.setAccount(data.getString("consNo"));
			cOrder.setOperator("wsgw");
			cOrder.setAmount(serContent.optInt("amount",0));
			cOrder.setChannel(data.getString("provinceId"));
			cOrder.setOrderNo(data.getString("busyNo"));
			int sta=0;
			if("0".equals(orderStatus))sta=-1;
			else if("3".equals(orderStatus))sta=1;
			else if("6".equals(orderStatus))sta=-2;
			cOrder.setStatus(sta);
			cOrder.setCreateTime(DateTimeUtil.strDate2UnixTime(data.getString("createTime")));
			onlineOrderList.add(cOrder);
		}
		return onlineOrderList;
    }
    
    public List<ChargeOrder> queryTransList(AccountBean account,int page,int limit) throws Exception {
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String body="{\"busyTypeCode\":\"\",\"srcTypeCode\":\"01\",\"subBusyTypeCode\":\"\",\"eStatusTypeCode\":\"\",\"showTime\":\"\",\"pageSize\":"+limit+",\"list\":[],\"keyWord\":\"\",\"token\":\""+account.getLogin_cookie()+"\",\"accountId\":\""+account.getInfo()+"\",\"rStatusTypeCode\":\"\",\"sSubBusyTypeCode\":\"\",\"sStatusTypeCode\":\"\",\"pageNo\":"+page+",\"startTime\":\"\",\"busyNo\":\"\",\"endTime\":\"\",\"serviceTypeCode\":\"\"}";
     	body=SmNetworkUtil.requestBody(body);
     	Response res = Http.create("https://osg-service.sgcc.com.cn:18600/osg-uc0004/member/c2/f02").proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(body).timeout(6).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
              throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
		log.info("[网上国网]查询订单列表---账号:{},结果:{},耗时:{},状态:{}",account.getAccount(),result,res.getTime(),res.getStatus());
		JSONObject jsonObject = JSONObject.fromObject(result);
		String code=jsonObject.getString("code");
		if(!"1".equals(code)) {
			throw new Exception(jsonObject.getString("message"));
		}
		JSONArray orderList = jsonObject.getJSONArray("data");
    	List<ChargeOrder> onlineOrderList=new ArrayList<ChargeOrder>();
		if(orderList.isEmpty())return onlineOrderList;
		for (int i = 0; i < orderList.size(); i++) {
			JSONObject data = orderList.getJSONObject(i);
			JSONObject serContent = data.getJSONObject("serContent");
			String orderStatus = serContent.optString("orderStatus");
			ChargeOrder cOrder=new ChargeOrder();
			cOrder.setAccount(data.getString("consNo"));
			cOrder.setOperator("wsgw");
			cOrder.setAmount(serContent.optInt("amount",0));
			cOrder.setChannel(data.getString("provinceId"));
			cOrder.setOrderNo(data.getString("busyNo"));
			int sta=0;
			if("0".equals(orderStatus))sta=-1;
			else if("3".equals(orderStatus))sta=1;
			else if("6".equals(orderStatus))sta=-2;
			cOrder.setStatus(sta);
			cOrder.setCreateTime(DateTimeUtil.strDate2UnixTime(data.getString("createTime")));
			onlineOrderList.add(cOrder);
		}
		return onlineOrderList;
    }
    
    public void accountCancelBind(AccountBean account)
    {
    	List<ChargeAccountBean> list=null;
		int succCount= 0;
		try {
			list = this.queryAccountList(account);
			if(list==null||list.size()==0)
			{
				return;
			}
			for (ChargeAccountBean chargeAccount : list) {
				try {
					this.delAccount(chargeAccount, account);
					succCount++;
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					continue;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		log.info("[网上国网]解绑户号---账号:{},解绑数:{},成功数:{}",account.getAccount(),list.size(),succCount);
    }
    
    public Map<String,String> orderDetail(OrderBean order,AccountBean account,int notify_type) throws Exception {
    	String[] orderNo=order.getOfficial_order_no().split("_");
    	Map<String, String> headers = new HashMap<String, String>();
    	//String url="https://payctl.95598pay.com/payunifycontroller/rest/payunify/zfbpay";
    	/*if(order.getPay_type().startsWith("wechat"))
    	{
    		url="https://payctl.95598pay.com/payunifycontroller/rest/payunify/wxpay";
    	}*/
    	String url="https://payctl.95598pay.com/payunifycontroller/rest/payunify/wxpay";
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("version", "2.2.3");
     	String bodys="data={\"data\":{\"PRE_ORDER_ID\":\""+orderNo[1]+"\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"header\":{\"REQTYPE\":\"1\",\"TIMESTAMP\":\"X2MmXeMHXejmXeUlXlXJY29A\",\"TOKEN\":\""+account.getLogin_cookie()+"\",\"CHANNEL_RESOURCE\":\"5\",\"SDKVERSION\":\"1.2021.05.14.01\",\"PLAT\":\"2\"}}";
     	Response res = Http.create(url).proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(bodys).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
             throw new Exception("网络链接失败，请重试!");
        }
        log.info("[网上国网]获取支付状态---订单号:{},结果:{},耗时:{},状态:{}",order.getOfficial_order_no(),result,res.getTime(),res.getStatus());
        JSONObject jsonObject=JSONObject.fromObject(result);
        JSONObject headerJson=jsonObject.getJSONObject("header");
        String repcd=headerJson.optString("repcd","");
        String repmsg=headerJson.optString("repmsg","");
        Map<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("status", "fail");
        if("MCA00001".equals(repcd))
        {
        	if("请勿重复付款".equals(repmsg)) {
        		resultMap.put("status", "success");
    			resultMap.put("orderNo", order.getOfficial_order_no());
        	}
    /*    	else if("系统错误".equals(repmsg)){
        		throw new Exception("网络链接失败，请重试!");
        	}*/
        }else if("MCA00000".equals(repcd)) 
        {
        	JSONObject dataJson=jsonObject.getJSONObject("data");
        	String ERRORMESSAGE=dataJson.optString("ERRORMESSAGE","");
        	if(ERRORMESSAGE.contains("当日支付次数超限")) {
        		AccountBean updateModel=new AccountBean();
        		updateModel.setId(account.getId());
        		if(account.isIs_temp())updateModel.setId(account.getTemp_id());
        		updateModel.setLogin_status(4);
        		updateModel.setUpdate_time(System.currentTimeMillis()/1000);
				updateModel.setRemarks(ERRORMESSAGE);
				accountService.update(updateModel);
        	}
        }
     	return resultMap;
    }
    
    public Map<String,String> orderDetail2(OrderBean order,AccountBean account,int notify_type) throws Exception {
    	String[] orderNo=order.getOfficial_order_no().split("_");
    	String url="https://osg-base.sgcc.com.cn:28660/osg-p0002/member/c9/f04";
    	Map<String, String> headers = new HashMap<String, String>();
    	long timestamp = System.currentTimeMillis();
     	headers.put("User-Agent", "wang shang guo wang/2.2.3 (iPhone; iOS 14.1; Scale/3.00)");
     	headers.put("wsgwType","ios");
     	headers.put("version","2.2.3");
     	headers.put("y",String.valueOf(timestamp));
     	headers.put("sessionId","IOSSession"+timestamp);
     	headers.put("deviceInfo","IOSSession"+timestamp);
     	headers.put("t",account.getLogin_cookie());
     	String bodys="{\"data\":{\"common\":{\"APPVERSION\":\"2.2.3\",\"CHANNEL_RESOURCE\":\"5\",\"ENCRYPTTYPE\":\"0\",\"PLAT\":\"3\",\"REQTYPE\":\"1\",\"SDKVERSION\":\"1.2021.08.19.01\",\"TOKEN\":\""+account.getLogin_cookie()+"\"},\"data\":{\"ORDER_ID\":\""+orderNo[1]+"\",\"TOKEN\":\""+account.getLogin_cookie()+"\"}},\"serviceCode\":\"f05\",\"source\":\"undefined\",\"target\":\"undefined\"}";
     	bodys=SmNetworkUtil.requestBody(bodys);
     	Response res = Http.create(url).proxy(account.getProxy_ip(),account.getProxy_port()).heads(headers).bodys(bodys).requestType(RequestType.JSON).post().send().getResponse();
		String result = res.getResult();
        if(res.getStatus()==0||StringUtils.isEmpty(result))
        {
             throw new Exception("网络链接失败，请重试!");
        }
        result=SmNetworkUtil.responseBody(result);
        log.info("[网上国网]获取支付状态---订单号:{},结果:{},耗时:{},状态:{}",order.getOfficial_order_no(),result,res.getTime(),res.getStatus());
        JSONObject jsonObject=JSONObject.fromObject(result);
        jsonObject=jsonObject.getJSONObject("data").getJSONObject("data");
        String RTN_CODE=jsonObject.optString("RTN_CODE","");
        String RTN_MESSAGE=jsonObject.optString("RTN_MESSAGE","");
        Map<String, String> resultMap = new HashMap<String, String>();
        resultMap.put("status", "fail");
        if("0".equals(RTN_CODE)&&RTN_MESSAGE.equals("该笔订单正在处理，请勿取消订单"))
        {
			resultMap.put("status", "success");
        }
     	return resultMap;
    }

    @Override
	public String getQueryOrderType() {
		// TODO Auto-generated method stub
		return this.queryOrderType;
	}

    @Override
	public void setQueryOrderType(String queryOrderType) {
		this.queryOrderType = queryOrderType;
	}

	@Override
	public Map<String, String> checkChargeAccount(ChargeAccountBean chargeAccount, AccountBean account){
		// TODO Auto-generated method stub
		ChargeAccountBean updateModel=new ChargeAccountBean();
		try {
			//queryAccount(chargeAccount, account);
			Map<String, String> resultMap = addAccount(chargeAccount, account);
			float LEAST_PAY_AMOUNT = Float.parseFloat(resultMap.get("LEAST_PAY_AMOUNT"))/100;
			updateModel.setStatus(0);
			updateModel.setLeast_pay_amount(LEAST_PAY_AMOUNT);
			String SENSITIVE_POWER_USER_ID=resultMap.get("SENSITIVE_POWER_USER_ID");
			updateModel.setOfficial_user_id(SENSITIVE_POWER_USER_ID);
			if(LEAST_PAY_AMOUNT>GlobalConfig.max_arrears_amount)
			{
				throw new Exception("欠费金额超限");
			}
			if(LEAST_PAY_AMOUNT>chargeAccount.getAmount())
			{
				throw new Exception("缴费金额少于欠费金额");
			}
			chargeAccount.setOfficial_user_id(SENSITIVE_POWER_USER_ID);
			accountService.resetBindFailCountById(account.getId());
			//this.delAccount(chargeAccount, account);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("检测充值账号异常,账号:{},充值账号{},{}", account.getAccount(),chargeAccount.getAccount(),e.getMessage());
        	if(e.getMessage().contains("网络链接失败"))
 			{
        		accountService.addProxyFailTimes(account.getId());
 			}
        	else if(e.getMessage().contains("请重新登录")) {
            	AccountBean updateAccount=new AccountBean();
            	updateAccount.setId(account.getId());
            	updateAccount.setLogin_status(2);
            	updateAccount.setLogin_cookie("");
            	updateAccount.setUpdate_time(System.currentTimeMillis()/1000);
                accountService.update(updateAccount);
            }
        	else if(e.getMessage().contains("系统处理繁忙")||e.getMessage().contains("操作过于频繁")) {
        		accountService.addBindFailCount(account.getId());
            }
        	else if(e.getMessage().contains("您添加的户号已达上限")) {
        		accountCancelBind(account);
            }
        	else if(e.getMessage().contains("请输入正确的用电户号"))
        	{
        		if(chargeAccount.getBind_fail_count()>2)
    			{
        			updateModel.setStatus(-2);
        			updateModel.setCharge_status(-1);
        			updateModel.setRemarks(e.getMessage());
    			}
        		else
        		{
        			chargeAccountService.addBindFailCount(chargeAccount.getId());
            		accountService.addBindFailCount(account.getId());
        		}
        	}
        	else
        	{
        		updateModel.setStatus(-2);
    			updateModel.setCharge_status(-1);
    			updateModel.setRemarks(e.getMessage());
        	}
		}
		finally {
			updateModel.setUpdate_time(System.currentTimeMillis()/1000);
			updateModel.setId(chargeAccount.getId());
			chargeAccountService.update(updateModel);
		}
		return null;
	}
	
	public static void main(String[] args) throws Exception {
		WsgwUtil wsgw=new WsgwUtil();
		AccountBean account=new AccountBean();
		account.setAccount("17065491417");
		account.setPassword("iwl39817");
		wsgw.login(account);//ssha47a8adc774249a58eaa693e9727a1eb
		//account.setLogin_cookie("98taf77e6a4f435d4d44bece33bd234e69b91");
		//wsgw.queryTransList(account, 1, 10);
		//Map<String, String> orderMap =new HashMap<>();
		//orderMap.put("ORDER_ID", "320210901130320267819");
		//wsgw.getPayUrl(orderMap, "alipay", account);
		//wsgw.queryTransList(account, 1, 10);
		ChargeAccountBean chargeAccount=new ChargeAccountBean();
		chargeAccount.setAccount("6502291612");
		//chargeAccount.setOfficial_user_id("osg-p:9f1006cf-b93a-40ab-90e5-c47b65b293e6");
		chargeAccount.setArea_code("33101");
		OrderBean order=new OrderBean();
		order.setPay_type("alipay");
		order.setAmount(5);
		//wsgw.queryAccount(account);
		//System.out.println(JSONUtil.toJson(wsgw.queryCertAuth(account)));
		//wsgw.createOrder(chargeAccount, account, order);
		
		
		//order.setOfficial_order_no("9889798240716316542d8cd7_420211020120562858077");
		//System.out.println(JSONUtil.toJson(wsgw.addAccount(chargeAccount, account)));
		//System.out.println(JSONUtil.toJson(wsgw.orderDetail(order, account, 2)));
	}
}
